import jsonpath
import json

obj=json.load(open('18jsonpath.json','r',encoding='utf-8'))

# 获取json文件下store下的book的jsonpath
# author_list=jsonpath.jsonpath(obj,'$.store.book[*].author')
# print(author_list)
#
# # 获取所有的jsonpath
# price_list=jsonpath.jsonpath(obj,'$..price')
# print(price_list)
#
# # 获取store下的所有元素标签
# price_list=jsonpath.jsonpath(obj,'$.store..')
# print(price_list)
#
# # store下面的所有的price
# price_list=jsonpath.jsonpath(obj,'$.store..price')
# print(price_list)
#
# # 获取第三本书
# book_list=jsonpath.jsonpath(obj,'$..book[1]')
# print(book_list)
#
# # 获取最后一本书
# book_list=jsonpath.jsonpath(obj,'$..book[(@.length-1)]')
# print(book_list)
#
# # 获取前两本书
# # book_list=jsonpath.jsonpath(obj,'$..book[0,1]')
# book_list=jsonpath.jsonpath(obj,'$..book[:2]')
# print(book_list)

# # 过滤出有版本号的书
# book_list=jsonpath.jsonpath(obj,'$..book[?(@.isbn)]')
# print(book_list)

# 那本书超过了30块
book_list=jsonpath.jsonpath(obj,'$..book[?(@.price>30)]')
print(book_list)